Fix: validate byte count in file_message.py decode handlers - #2980
Merged
janiversen merged 6 commits intoJul 24, 2026
Merged
Conversation
Adds bounds checking to ReadFileRecordRequest, WriteFileRecordRequest, and ReadFifoQueueResponse decode handlers, consistent with pymodbus-dev#2974 and pymodbus-dev#2977. Raises ModbusException instead of struct.error when byte_count exceeds actual payload length.
Contributor
Author
|
Hi @janiversen, I have added three tests covering the new validation branches (test_read_file_record_request_decode_invalid_byte_count, test_write_file_record_request_decode_invalid_byte_count, test_read_fifo_queue_response_decode_invalid_count). All 16 CI checks are now passing with 100% coverage. Could you take another look when you get a chance? Thanks! |
Contributor
Author
|
Thank you so much for your assistance :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Adds bounds checking to three decode handlers in
pymodbus/pdu/file_message.py,consistent with the fixes applied in #2974 and #2977.
Changes:
ReadFileRecordRequest.decode: validatebyte_countagainstlen(data)before iteratingWriteFileRecordRequest.decode: validatebyte_countagainstlen(data)before loopingReadFifoQueueResponse.decode: validatecountagainstlen(data)before iteratingPreviously, an oversized
byte_countfield causedstruct.unpack()to raisestruct.error, which escaped theModbusException/ValueError/IndexErrorhandler in
DecodePDU.decode(). The fix raisesModbusExceptioninstead,matching the behaviour added in #2974 and #2977.
Related to security advisory GHSA-xxxx (private).